<?php
class User_utils {
	
	private $ci;
	
	public function __construct()
	{
		$this->ci = & get_instance();
	}
	
	public function filter_login()
	{
		session_start();
		$user_id =  $this->get_session_attribute(Variable::SESSION_USER_ID);
		
		$is_login = $user_id > 0;
		if(!$is_login)
		{
			redirect('/?error='.Variable::ERROR_LOGIN);
			die();
		}
	}
	
	public function get_session_attribute($attribute_name)
	{
		$value = $this->ci->session->userdata($attribute_name);
		if(!$value && isset($_SESSION[$attribute_name]))
		{
			$value = $_SESSION[$attribute_name];
		}
		
		return $value;
	}
	
	public function get_change_key($mail)
	{
		$key = $mail.uniqid();
		return md5($key);
	}
}
?>